package homework.test1;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Demo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //1.获取公共对象
        Class clazz = Class.forName("homework.test1.Student");
        Constructor constructor = clazz.getConstructor();
        Student stu = (Student) constructor.newInstance();
        System.out.println(stu);

        //2.获取私有对象
        Constructor declaredConstructor = clazz.getDeclaredConstructor(String.class);
        declaredConstructor.setAccessible(true);
        Student stu2 = (Student) declaredConstructor.newInstance("张三");
        System.out.println(stu2);
    }
}
